/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Control;

import Entity.Owner;
import Services.OwnerService;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author microraptor
 */
public class ControlOwner {
    EntityManagerFactory emf;
    EntityManager em;

    public ControlOwner() {
        emf = Persistence.createEntityManagerFactory("HPVAS-2013-1-BPU");
    }
    
    public void crearOwner (String name, String lastName, String ssn, Date birthDate, String birthPlace){
        OwnerService os = new OwnerService(emf);
        Owner o = new Owner(name,lastName,ssn,birthDate ,birthPlace);
        os.crear(o);
    }
    
    public void editOwner (Owner owner) throws Exception{
        OwnerService os = new OwnerService(emf);
        os.edit(owner);
    }
    
    public void removeOwner (long id){
        OwnerService os = new OwnerService(emf);
        try {
            os.destroy(id);
        }catch(Exception e ){
            
        }
    }
    
    public List<Owner> readAllOwner (){
        OwnerService os = new OwnerService(emf);
        return os.findOwnerEntities();
    }
    
    public Owner readOwner(Long id){
        OwnerService os = new OwnerService(emf);
        return os.findOwner(id);
    }

    
}
